import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: () => import("../views/home/index.vue"),
    // 路由向路由切换过滤参数。1:一级路由
    meta: {
      index: 1,
    },
  },
  {
    path: "/category",
    name: "Category",
    component: () => import("../views/category/index.vue"),
    meta: {
      index: 1,
    },
  },
  {
    path: "/cart",
    name: "Cart",
    component: () => import("../views/cart/index.vue"),
    meta: {
      index: 1,
      // 导航守卫中 对要进行登录的页面进行拦截的标记
      auth: true,
    },
  },
  {
    path: "/me",
    name: "Me",
    component: () => import("../views/me/index.vue"),
    meta: {
      index: 1,
      auth: true,
    },
  },
  {
    path: "/product-list",
    name: "ProductList",
    component: () => import("../views/products/product-list.vue"),
    meta: {
      index: 2,
    },
  },
  {
    path: "/product/:id",
    name: "ProductDetail",
    component: () => import("../views/products/product-detail.vue"),
    meta: {
      index: 3,
    },
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/login/login.vue"),
    meta: {
      index: 2,
    },
  },
  {
    path: "/register",
    name: "Register",
    component: () => import("../views/register/register.vue"),
    meta: {
      index: 3,
    },
  },
  {
    path: "/profile",
    name: "Profile",
    component: () => import("../views/profile/profile.vue"),
    meta: {
      index: 2,
      auth: true,
    },
  },
];

const router = new VueRouter({
  routes,
});

export default router;
